{extend name="ashippingmanagement2/Public/base" /}
{block name="container"}
<style>
    .error{
        color:red;
    }
</style>
<script>
    $(function (){
        $('#uploadify').uploadifive({
            'buttonText': '附件',
            'width': '50px',
            'height': '30px',
            'fileObjName':"bx_fy2",
            'queueID':"uploadifyQueue",
            'queueSizeLimit': 15,//这里我只允许单个图片上传
            'uploadScript':'{:url("ashippingmanagement2/uploadifive")}',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.success) {
                    var dataValue = JSON.stringify(data.data);
                    file.queueItem.attr('uri',dataValue);
                }else {
                    file.queueItem.addClass('error');
                    file.queueItem.find('.fileinfo').html('-'+data.message);
                }
            }
        });
    })
</script>
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">添加二级出货</h2>
</div>
<!-- 标题 -->
<div>
    <form id="form_id" action="" class="form-inline" method="post">
        <table class="row-margin-top tab-content table-bordered table text-left" border="1">
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">日期<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control layer-date validate[required,custom[date]]" name="fy2Date"
                           id="stairTwo"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width: 140px" class="text-right"><label for="" class="form-label">经销商名称<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="" name="jxs" id="jxs"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="jxs_id" id="jxs_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectJxs" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">类型<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <label class="radio-inline">
                        <input type="radio" id="shipNet" checked value="0" name="shipKind">出货至网点
                    </label>
                    <label class="radio-inline">
                        <input type="radio" id="shipSystem" value="1" name="shipKind">出货至系统
                    </label>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right shipLab"><label for=""
                                                                               class="form-label">网点名称</label><span
                        class="colorRed">*</span>：
                </td>
                <td>
                    <!--<div class="form-group" id="NetDiv">-->
                    <!--<input type="text" class="form-control" name=""><a href="javascript:;" id="selectNet">选择</a>-->
                    <!--</div>-->
                    <!--<div class="form-group" id="SysDiv" style="display: none;">-->
                    <!--<input type="text" class="form-control" name=""><a href="javascript:;" id="SysDiv">选择</a>-->
                    <!--</div>-->
                    <div class="col-xs-4">
                        <div class="input-group" id="NetDiv">
                            <input type="text" class="form-control validate[required]" value="" name="wd" id="wd"
                                   placeholder="请选择">
                            <input type="hidden" name="wd_id" id="wd_id" value="">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div class="input-group" id="SysDiv" style="display: none;">
                            <input type="text" class="form-control validate[required]" value="" name="xt" id="xt"
                                   placeholder="请选择">
                            <input type="hidden" name="xt_id" id="xt_id" value="">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">产品名称<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="" name="cp" id="cp"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="cp_id" id="cp_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectCp" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">单位<span
                        class="colorRed">*</span>：</label></td>
                <td>
                    <select name="dw" id="dw" class="form-control validate[required]">
                        <option value="">请选择</option>
                        <option value="箱">箱</option>
                        <option value="盒">盒</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">供货价(元)<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control validate[required,custom[number]]" name="ghjMoney"></td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">供货数量<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control validate[required,custom[integer]]" name="ghNum">注：退货可录入负数。</td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">金额(元)<span
                        class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control validate[required,custom[number]]" name="money"></td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">销售人员：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="" name="xsUser" id="xsUser"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="xsUser_id" id="xsUser_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectXsUser" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">批号/批次：</label></td>
                <td><input type="text" class="form-control" name="phpc"></td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right" rowspan="2"><label for="" class="form-label">备注：</label>
                </td>
                <td>
                    <textarea name="des" id="des" class="form-control validate[maxSize[100]]" rows="2"
                              style="user-select:none;width: 70%"></textarea><span
                        style="vertical-align: bottom;">100</span>
                </td>
            </tr>
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px" id="upfileDiv">
            <!--<input type="file" id="exampleInputFile" name="exampleInputFile">-->
            <input type="button" name="uploadify" id="uploadify">
            <div id="uploadifyQueue"></div>
            <p class="help-block" style="color:#1295d2">注：最多上传15个文件，每个文件小于50M,支持格式：</p>
            <p class="help-block" style="color:#1295d2">
                jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav</p>
        </div>
        <div class="text-center">
            <button class="btn btn-info" type="button" onclick="submits(1);">提交</button>
            <span class="lr_5"></span>
            <button class="btn btn-success" onclick="submits(2);">保存并再添一条</button>
            <span class="lr_5"></span>
            <button class="btn btn-warning" type="button" onclick="back()">返回</button>
        </div>
    </form>
</div>
<script>
    //网点
    function sdNet(id){
        $("#wd").bsSuggest('destroy');
        var catbs = $("#wd").bsSuggest({
            url: "{:url('select/netjson')}?keyword=" + id,
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        });
        //网点名称
        $("#wd").bsSuggest('enable');
        catbs.on('onSetSelectValue', function (e, re) {
            $('#wd').val(re.key);
            $('#wd_id').val(re.id);
            $("#cp").bsSuggest('destroy')
            $("#cp").bsSuggest({
                // url: "{:url('select/product')}?keyword="+keyword.id,
                url: "{:url('select/product')}",
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, re) {
                $('#cp').val(re.key);
                $('#cp_id').val(re.id);
            });
        });
    }
    laydate({
        elem: "#stairTwo",
        event: "focus"
    })

    $("input:radio[name=shipKind]").click(function () {
        if ($("#shipNet").prop("checked") != true) {
            $(".shipLab").children('label').text('系统名称')
            $('#SysDiv').show();
            $('#NetDiv').hide();
        } else {
            $(".shipLab").children('label').text('网点名称')
            $('#SysDiv').hide();
            $('#NetDiv').show();
        }
        ;
    });
    //表单验证
    $('#form_id').validationEngine('attach', {
        promptPosition: 'bottomRight'
    });
    function submits(type){
        if($('#form_id').validationEngine('validate')){
            var enclosure_url = '';
            $('form').find('#uploadifyQueue .uploadifive-queue-item').each(function(){
                if($(this).attr('uri')){
                    if(enclosure_url==''){
                        enclosure_url+=$(this).attr('uri');
                    }else {
                        enclosure_url+="||"+$(this).attr('uri');
                    }
                }
            });
            $.post("{:url('Ashippingmanagement2/add')}",$('form').serialize()+'&file='+enclosure_url,function(re){
                if(re.success){
                    if(type == 2){
                        swal({title: '添加成功，继续添加！', text: '', type: "success"});
                    }else{
                        back();
                    }
                }else{
                    swal({title: re.msg, text: '', type: "warning"});
                }
            },'json')
        }
    }

    //弹出经销商树状
    $('#selectJxs').click(function () {
        layer.open({
            type: 2,
            area: ['60%', '60%'],
            maxmin: true,
            content: '{:url("Ashippingmanagement/selectJXS")}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents();
                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                if(id){
                    $('#jxs').val(name);
                    $('#jxs_id').val(id);
                    sdNet(id);
                }
                layer.close(i);
            }
        });
        return false
    });
    //搜索经销商
    $("#jxs").bsSuggest({
        url: "{:url('select/jxsjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias: {title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {
    }).on('onSetSelectValue', function (e, re) {
        $('#jxs').val(re.key);
        $('#jxs_id').val(re.id);
        sdNet(re.id);
    });
    //产品单品搜索自动补全
    $("#cp").bsSuggest({
        url: "/index.php/index/select/productjson",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword);
        $('#cp').val(keyword.key);
        $('#cp_id').val(keyword.id);
    });

    //弹出选择产品树状
    $('#selectCp').on('click',function () {
        layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'{:url("Ashippingmanagement/selectProduct")}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents();
                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                if(id){
                    $('#product').val(name);
                    $('#product_id').val(id);
                }
                layer.close(i);
            }
        });
        return  false
    })
    //销售人员搜索自动补全
    $("#xsUser").bsSuggest({
        url: "/index.php/index/apcaiwu/cnamejson",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword);
        $('#xsUser').val(keyword.key);
        $('#xsUser_id').val(keyword.id);
    });
    //弹出选择销售人树
    $('#selectXsUser').click(function (){
        layer.open({
            type:2,
            area:['60%','60%'],
            title:'销售人',
            maxmin:true,
            content:'/index.php/index/apcaiwu/selectCname',
            btn:['确定','关闭'],
            btnAlign:'c',
            yes:function (i,o) {
                var id = $(o).find('iframe').contents().find('#renyuan').val()
                var name = $(o).find('iframe').contents().find('#renyuanname').val()
                if(id){
                    $('#xsUser').val(name);
                    $('#xsUser_id').val(id);
                }
                layer.close(i)
            }
        });
        return  false
    });
</script>
{/block}
